package Servlet;

import DAO.BookDao;
import DAO.RecordDao;
import DAO.UserDao;
import DataClass.Book;
import DataClass.Page;
import DataClass.Record;
import DataClass.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/listUserServlet")
public class ListUserServlet extends HttpServlet {
    private RecordDao dao=new RecordDao();
    protected void service(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
        // 获取分页参数
        int start = 0;
        int count = 6;

        try {
            start = Integer.parseInt(req.getParameter("page.start"));
            count = Integer.parseInt(req.getParameter("page.count"));
        } catch (Exception e) {
        }

        Page page = new Page(start, count);

        List<Record> records = null;
        try {
            records = RecordDao.list(page.getStart(), page.getCount());
        } catch (Exception e) {
            e.printStackTrace();
        }
        int total = 0;
        try {
            total = RecordDao.getTotal();
        } catch (Exception e) {
            e.printStackTrace();
        }
        page.setTotal(total);

        req.setAttribute("records", records);
        req.setAttribute("page", page);

        req.getRequestDispatcher("/list_user.jsp").forward(req, resp);
    }
}
